#ifndef __GAME_DEF_H__
#define __GAME_DEF_H__

#include "game_config.h"

#ifndef INTERFACES
#define INTERFACES struct
#endif

#if CGAME_TARGET_PLATFORM == CGAME_WIN
#define __INT64__ signed __int64
#define __UINT64__ unsigned __int64
#else
#define __INT64__ long long
#define __UINT64__ unsigned long long
#endif

typedef signed char INT8;
typedef signed short INT16;
typedef signed int INT32;
// typedef __INT64__ INT64;

typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
typedef __UINT64__ UINT64;

typedef UINT8 BYTE;

#if CGAME_TARGET_PLATFORM == CGAME_PLATFORM_MAC
#define __BOOL__ signed char
#else
#define __BOOL__ int
#endif

typedef __BOOL__ BOOL;

typedef char CHAR;

#ifndef TRUE
#define TRUE (1)
#endif

#ifndef FALSE
#define FALSE (0)
#endif

typedef float FLOAT;

#ifndef INT8_MIN
#define INT8_MIN    (-0x7f - 1)
#endif

#ifndef INT16_MIN
#define INT16_MIN   (-0x7fff - 1)
#endif

#ifndef INT32_MIN
#define INT32_MIN   (-0x7fffffff - 1)
#endif

#ifndef INT64_MIN
#define INT64_MIN   (-0x7fffffffffffffff - 1)
#endif

#ifndef INT8_MAX
#define INT8_MAX    0x7f
#endif

#ifndef INT16_MAX
#define INT16_MAX   0x7fff
#endif

#ifndef INT32_MAX
#define INT32_MAX   0x7fffffff
#endif

#ifndef INT64_MAX
#define INT64_MAX   0x7fffffffffffffff
#endif

#ifndef UINT8_MAX
#define UINT8_MAX   0xff
#endif

#ifndef UINT16_MAX
#define UINT16_MAX  0xffff
#endif

#ifndef UINT32_MAX
#define UINT32_MAX  0xffffffff
#endif

#ifndef UINT64_MAX
#define UINT64_MAX  0xffffffffffffffff
#endif

typedef UINT64 mseconds_t;

INTERFACES CGameObject{
public :
  CGameObject(){}

  virtual BOOL init(){
    return TRUE;
  }
};

class CGameRef :virtual public CGameObject
{
private:
  UINT32 _referenceCount;

public:
  CGameRef() : _referenceCount(1)
  {
  }

  /**
   * Retains the ownership.
   *
   * This increases the Ref's reference count.
   *
   * @see release, autorelease
   * @js NA
   */
  void retain(){
    ++_referenceCount;
  };

  /**
   * Releases the ownership immediately.
   *
   * This decrements the Ref's reference count.
   *
   * If the reference count reaches 0 after the descrement, this Ref is
   * destructed.
   *
   * @see retain, autorelease
   * @js NA
   */
  virtual void release(){
    --_referenceCount;

    if(0 == _referenceCount){
      delete this;
    }
  };

  void autorelease();
  virtual ~CGameRef(){};

  /**
   * Returns the Ref's current reference count.
   *
   * @returns The Ref's reference count.
   * @js NA
   */
  UINT32 getReferenceCount() const{
    return _referenceCount;
  };
};






#endif
